package be.kuleuven.cs.mop.gui.dialogs;


import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import be.kuleuven.cs.mop.app.controllers.Controllers;



/**
 * Represents an {@link ActionDialog} of which the content
 * 	is changed dynamically at runtime due to user interaction
 */
public abstract class DynamicActionDialog<T> extends ActionDialog {
	private static final long serialVersionUID = 1L;
	
	
	public DynamicActionDialog(final Frame parent, final String title,
			final Controllers controllers) {
		super(parent, title, controllers);
	}
	
	
	
	protected abstract T getSelection();
	
	protected abstract void update(T selection) throws Exception;
	
	
	
	
	
	
	
	
	
	
	protected class UpdateListener implements ActionListener {
		
		@Override
		public void actionPerformed(final ActionEvent event) {
			try {
				update(getSelection());
			} catch (final Exception e) {
				//	ignored
				e.printStackTrace();
			}
			
			invalidate();
			pack();
		}
		
	}
	
}